// 规避ts全局变量重复申明提示
export {}

const hello = (name: string): void => {
  console.log(`hello ${name}`)
}

hello('TypeScript')
// hello(100)

let age
age = 100
age = 'ddd'

const nums = [110, 120, 119, 112]
let res = nums.find((i) => i > 0)
let num1 = res as number
num1 * num1
let num2 = <number>res // JSX下不能使用，语法冲突
num2 * num2

interface Post {
  title: string
  content: string
  subTitle?: string // 可选
  readonly summary: string // 只读
}

function printPost(post: Post): void {
  console.log(post.title)
  console.log(post.content)
}

let helloPost: Post = {
  title: 'title',
  content: 'content',
  summary: 'summary',
}
// helloPost.summary = 'new summary'
// printPost(helloPost)

//任意成员接口
interface Cache {
  [key: string]: string
}
let cache: Cache = {
  hello: 'Hello Cache',
}
cache.newProp = 'new prop value'

function createArray<T>(length: number, value: T): T[] {
  let arr = Array<T>(length).fill(value)
  return arr
}

let strarr = createArray<string>(3, 'hello')
console.log(strarr)
